#ifndef __BEZIERCURVE_H__
#define __BEZIERCURVE_H__

#include <vector>
#include "Bernstein.h"
#include <stdarg.h>

class BezierCurve{
 public:
 BezierCurve(std::vector<Vector4> controlpoints) : controlpoints(controlpoints), bernsteinpolynomials() {
		if (controlpoints.size() == 0)
			throw "Need more control points than 0";

		Vector4 p3(controlpoints[0]);
		size_t current_controlpoint=1;

		do {
			Vector4 p0=p3;
			Vector4 p1(controlpoints[current_controlpoint++]);
			Vector4 p2(controlpoints[current_controlpoint++]);
			Vector4 p3(controlpoints[current_controlpoint++]);
			bernsteinpolynomials.push_back(Bernstein(p0,p1,p2,p3));
		} while (current_controlpoint < controlpoints.size());
	}
	
	BezierCurve(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3) {
		bernsteinpolynomials.push_back(Bernstein(p0,p1,p2,p3));
	}

	Vector4 evaluate(double t) {
		int bernstein_index = (int)floor(t);
		return bernsteinpolynomials[bernstein_index].evaluate(t);
	}
	
 private:
	std::vector<Vector4> controlpoints;
	std::vector<Bernstein> bernsteinpolynomials;
};

#endif
